package edu.turtlekit2.warbot.exec;

import java.util.List;
import java.util.WeakHashMap;

import madkit.kernel.Message;
import edu.turtlekit2.warbot.WarBrain;
import edu.turtlekit2.warbot.WarExec;
import edu.turtlekit2.warbot.agents.WarExplorer;
import edu.turtlekit2.warbot.message.WarMessage;
import edu.turtlekit2.warbot.message.WarMessageFinal;
import edu.turtlekit2.warbot.percepts.Percept;
import edu.turtlekit2.warbot.team1.BrainExplorer1;
import edu.turtlekit2.warbot.team2.BrainExplorer2;

public class WarExplorerExec extends WarExec {
	
	private WarBrain								_mineBrain = null;
	private WarExplorer								_mineExplorer = null;

	public WarExplorerExec(WarExplorer we){
		_mineExplorer = we;
		if(_mineExplorer.getTeam().equals("1")) {
			_mineBrain = new BrainExplorer1(this);
		}else{
			_mineBrain = new BrainExplorer2(this);
		}
	}
	
	public WarMessageFinal getMessage(){
		WarMessageFinal retour = null;
		Message m = _mineExplorer.nextMessage();
		if(m != null){
			if(m instanceof WarMessage){
				retour = new WarMessageFinal((WarMessage)m, _mineExplorer.xcor(), _mineExplorer.ycor());
			}
		}
		
		return retour;
	}
	
	public void setRandomHeading(){
		_mineExplorer.randomHeading();
	}
	
	public void setHeading(double angle){
		_mineExplorer.setHeading(angle);
	}

	@Override
	public String action() {
		
		return _mineBrain.action();
	}

	@Override
	public List<Percept> getPercepts() {
		return _mineExplorer.getPercept();
	}
}